# -*- coding: utf-8 -*-
# @Time: 2021/8/24 15:46
# @File: arg-20.py
# @DESC:
class Solution:
    def __init__(self):
        self.map = {
            "(": 1,
            ")": -1,
            "{": 2,
            "}": -2,
            "[": 3,
            "]": -3
        }

    def isValid(self, s: str) -> bool:
        print(s)
        map = self.map
        lent = len(s)
        # 个数为奇数，肯定不对称
        if lent % 2 != 0 or lent == 0:
            return False
        flag = 0
        for i in range(lent - 1):
            if map[s[i]] < 0 and map[s[i + 1]] > 0:
                split = s[flag:i + 1]
                if len(split)<=1:
                    return False
                if flag == 0 and len(split) % 2 == 1:
                    split = split[1:]
                print(split)
                if self.check(split):
                    flag = i + 1
                else:
                    return False
        split = s[flag:lent]
        if len(split) % 2 == 1:
            split = split[flag:lent - 1]
        print(split)
        return self.check(split)

    def check(self, s):
        map = self.map
        for i in range(int(len(s) / 2)):
            im = len(s) - i - 1
            if map[s[i]] + map[s[im]] != 0 or map[s[i]] < 0:
                return False
        return True


def isValid(s: str) -> bool:
    # 两种情况 1.完全对称 2.连续对称
    map = {
        "(": 1,
        ")": -1,
        "{": 2,
        "}": -2,
        "[": 3,
        "]": -3
    }
    lent = len(s)
    # 个数为奇数，肯定不对称
    if lent % 2 != 0 or lent == 0:
        return False
    # 连续对称
    if map[s[0]] + map[s[1]] == 0:
        for i in range(0, lent, 2):

            if map[s[i]] + map[s[i + 1]] != 0 or map[s[i]] < 0:
                return False
    else:
        # 完全对称
        for i in range(int(lent / 2)):
            if map[s[i]] + map[s[lent - i - 1]] != 0 or map[s[i]] < 0:
                return False

    return True

#官方解答
def isValid2(s: str) -> bool:
    print()

# s = "){"
s = "(){}}{"
# s = "()[]{}"
# s = "(([]){})"
# s = "()"
r = isValid2(s)
print(r)
